import axios from 'axios'
import { Indicator, Toast } from 'mint-ui'

const ajax = axios.create({
  baseURL: 'http://www.xiongmaoyouxuan.com'
})

//  拦截器
ajax.interceptors.request.use(config => {
  Indicator.open('加载中...')
  return config
})

ajax.interceptors.response.use(resp => {
  Indicator.close()
  if (resp.status === 200 && resp.data.code === 200) {
    return resp.data.data
  } else {
    Toast('请求失败')
    return resp.statusText
  }
})

export const getDataById = (id, start) => {
  return ajax.get(`/api/tab/${id}?start=${start}`)
}

export const getTabs = () => ajax.get('/api/tabs')

export const getDetail = id => ajax.get(`/api/detail?id=${id}`)
